﻿using System;
using UnityEngine;
using UnityEngine.UI;
using System.Collections.Generic;

class ShortcutPanel : PanelBase
{
    [SerializeField]
    private Button playerBtn;
    [SerializeField]
    private Button bagBtn;
    [SerializeField]
    private Image HpImg;

    private List<SkillIcon> skillIcons;

    public override void RegisterListeners()
    {
        base.RegisterListeners();
        playerBtn.onClick.AddListener(ShowPlayerPanel);
        bagBtn.onClick.AddListener(ShowBagPanel);
        Mgr.fightMgr.fightEvent.AddListener(FightEvent.PlayerChangeHp, PlayerChangeHpHandler);
        skillIcons = new List<SkillIcon>()
        {
            transform.Find("Skill").Find("SkillGrid1").GetComponent<SkillIcon>(),
            transform.Find("Skill").Find("SkillGrid2").GetComponent<SkillIcon>(),
            transform.Find("Skill").Find("SkillGrid3").GetComponent<SkillIcon>()
        };

        SetSkill(EnumSkillId.skill1, 1);
        SetSkill(EnumSkillId.skill2, 2);
        SetItem(EnumItem.HPDrug, 3);
        Show();
    }

    public override void Show()
    {
        base.Show();
        Debug.Log("showPanel");
    }

    public override void Hide()
    {
        base.Hide();
        Debug.Log("hidePanel");
    }

    private void PlayerChangeHpHandler(object data)
    {
        int[] hpArr = data as int[];
        HpImg.fillAmount = (float)hpArr[0] / hpArr[1];
    }

    private void ShowPlayerPanel()
    {

    }

    private void SetSkill(int skillId, int GridIdx)
    {
        SkillIcon icon = skillIcons[GridIdx - 1];
        icon.SetSkillInfo(Mgr.skillMgr.GetSkillInfo(skillId));
    }

    private void SetItem(int ItemModelId, int GridIdx)
    {
        SkillIcon icon = skillIcons[GridIdx - 1];
        icon.SetItemInfo(Mgr.bagServerMgr.GetItemModelInfo(ItemModelId));
    }

    public override void PanelUpdate()
    {
        if(Input.GetKeyDown(KeyCode.B))
        {
            ShowBagPanel();
        }
    }

    private void ShowBagPanel()
    {
        if (Mgr.panelMgr.IsPanelShow(EnumPanelType.BagPanel))
            Mgr.panelMgr.HidePanel(EnumPanelType.BagPanel);
        else
            Mgr.panelMgr.ShowPanel(EnumPanelType.BagPanel);
    }
}

